package c2.cross.business.championrace.temp;

import cate.game.framework.index.IndexedList;
import cate.game.pvp.championrace.data.ChampionRaceRankRwd;
import org.apache.commons.compress.utils.Lists;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class ChampionRaceTempRankRwdData extends IndexedList<String, ChampionRaceRankRwd> {
    public void upsert(List<ChampionRaceRankRwd> rankRwdList) {
        for (ChampionRaceRankRwd rankRwd : rankRwdList) {
            if (!contains(rankRwd.getSrvIdIndexName(), rankRwd.getIndexedKey())) {
                addValue(rankRwd);
                addIndex(rankRwd.getSrvIdIndexName(), rankRwd.getIndexedKey(), rankRwd);
            }
        }
    }

    public List<ChampionRaceRankRwd> getRankRwdList(String indexKey) {
        Map<String, ChampionRaceRankRwd> indexMap = getIndex(indexKey);
        return Objects.nonNull(indexMap) ?
                new ArrayList<>(indexMap.values())
                : Lists.newArrayList();
    }
}
